package com.jumi.microservice.material.controller;

import com.jumi.common.log.annotation.Log;
import com.jumi.common.log.enums.BusinessType;
import com.jumi.microservice.common.base.AjaxResult;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.excel.utils.ExcelUtils;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.framework.log.domain.SysOperLog;
import com.jumi.microservice.material.service.ISysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/operlog")
@Api(tags = {"【基础资料】操作日志接口"})
public class SysOperlogController extends BaseController
{
    @Resource
    private ISysOperLogService operLogService;

    @GetMapping("/list")
    @ApiOperation("分页获取日志接口")
    public TableDataInfo<List<SysOperLog>> list(SysOperLog operLog)
    {
        startPage();
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "供应链管理-基础管理-操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLog operLog) throws IOException
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtils<SysOperLog> utils = new ExcelUtils<SysOperLog>(SysOperLog.class);
        utils.exportExcel(response,list, "操作日志");
    }

    @DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @Log(title = "供应链管理-基础管理-操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return AjaxResult.success();
    }

    @PostMapping
    public AjaxResult add(@RequestBody SysOperLog operLog)
    {
        return toAjax(operLogService.insertOperlog(operLog));
    }
}
